﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ColorLife.Core.Helper;
using DLUProject.Domain;
using DLUProject.Services;
public partial class QuanLyKTX_Phong_ThemSinhVien : BaseUserControl
{
    public IServices<SinhVien> _sinhVienService { get; set; }
    public PhongSinhVienModel Model { get; set; }
    public PhongExtension _phongServiceExt { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public int IDPhong
    {
        get
        {
            if (Request.QueryString["id"] != null)
                return Server.UrlEncode(Request.QueryString["id"]).ToInt();
            return -1;
        }
    }
    protected override void OnInit(EventArgs e)
    {
        if (!IsPostBack)
        {
            Model = _phongServiceExt.GetThongTinPhong(IDPhong);
            if (Model == null || Model.Phong == null)
            {
                Response.Redirect("Default.aspx");
            }
            if (!Model.Phong.IsSanSang)
            {
                Response.Redirect("Default.aspx?controller=ctphong&id=" + IDPhong);
            }
            LoadDataSinhVien();
        } 
        base.OnInit(e);
    }
    void LoadDataSinhVien( )
    {
        int total = 0;
        int pageSize = 10;
        int pageNum = 1;
        if (Request.QueryString[PagingControl1.QueryStringKey] != null)
        {
            pageNum = int.Parse(Server.HtmlEncode(Request.QueryString[PagingControl1.QueryStringKey]));
        }
        else pageNum = 1;
       
        var items = _sinhVienService.Table.Where(c => c.GioiTinh == Model.Phong.LoaiPhong && c.TrangThai == (int)TrangThaiSinhVien.Dang_Cho);
        rptItems.DataSource = _sinhVienService.Paging(items, pageSize, pageNum, out total);
        rptItems.DataBind();

        rptItems.DataBind();
        PagingControl1.TotalRecord = total;
        PagingControl1.CurrentPage = pageNum;
        PagingControl1.PageSize = pageSize;
    }
}